package com.mrd.serverconnect.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mrd.serverconnect.R;
import com.mrd.serverconnect.been.abs.SimpleNameValueBeanInterface;

import java.util.List;

public class SimpleNameValueAdapter extends BaseAdapter {

    private final Context context;
    private final List<SimpleNameValueBeanInterface> list;
    private int adapterSourceId = 0;
    private int itemViewSourceId = 0;
    private int showPosition;


    public SimpleNameValueAdapter(Context context,List<SimpleNameValueBeanInterface> list,int adapterSourceId,int itemViewSourceId){
        this.context=context;
        this.list=list;
        this.adapterSourceId = adapterSourceId;
        this.itemViewSourceId = itemViewSourceId;
    }



    public SimpleNameValueAdapter(Context context, List<SimpleNameValueBeanInterface> list) {
        this.context=context;
        this.list=list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public SimpleNameValueBeanInterface getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyHolder holder;
        if (convertView==null){
            holder=new MyHolder();
            convertView = LayoutInflater.from(context).inflate(itemViewSourceId==0?R.layout.item_chosee:itemViewSourceId,parent,false);
            holder.tvChoose = convertView.findViewById(R.id.tv_choose);
            convertView.setTag(holder);
        }else {
            holder = (MyHolder) convertView.getTag();
        }
        SimpleNameValueBeanInterface bean = (SimpleNameValueBeanInterface)list.get(position);
        holder.tvChoose.setText(bean.getName());
        if (showPosition==position){
            holder.tvChoose.setTextColor(context.getResources().getColor(R.color.color_blue));
        }else {
            holder.tvChoose.setTextColor(context.getResources().getColor(R.color.color_blue));
        }
        holder.tvChoose.setTextSize(TypedValue.COMPLEX_UNIT_SP,25);
        return convertView;
    }
    class MyHolder{
        TextView tvChoose;
    }
}
